package com.hanggold.netty.client;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;

/**
 * netty 一切核心及channel .
 *
 * @author <a href="mailto:sunmch@163.com">smc</a>
 * @date 2021-11-28 10:18
 * @since 1.0.0
 **/
@AllArgsConstructor
public class EchoClient {
    
    private String address;
    
    private  int port;
    
    public static void main(String[] args) {
    
    }
    
    @SneakyThrows
    public void start() {
        final Bootstrap bootstrap = new Bootstrap();
        final NioEventLoopGroup eventExecutors = new NioEventLoopGroup();
        bootstrap.group(eventExecutors).channel(NioSocketChannel.class).remoteAddress(address, port).handler(new ChannelInitializer<SocketChannel>() {
            @Override
            protected void initChannel(final SocketChannel ch) throws Exception {
                //                ch.pipeline().addLast()
            }
        });
    
        final ChannelFuture channelFuture = bootstrap.connect().sync();
        final Channel channel = channelFuture.channel();
//        channel.writeAndFlush()
        final ChannelFuture sync =channel.closeFuture().sync();
    }
    
}
